# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: api_util.py
# Time: 14:16

from airtest.core.android.android import *

from common.util.env_util import EnvironmentConfiguration
from common.util.file_util import get_data_file_path
from common.util.read_util import OperationYaml

env = EnvironmentConfiguration()


def config_data():
    config = {
        "devices": devices(),
        "version": env.get_apppackage_version()[0],
        "environment": env.get_environment()
    }
    return config


def devices():
    '''设备参数'''
    return [tmp[0] for tmp in ADB().devices()]


def get_yaml_data(file_name):
    file = get_data_file_path(file_name)
    element_dict = {}
    id = "{}"
    read = OperationYaml(file).get_yaml_data()
    app_package = env.get_apppackage_version()[1]
    for key, value in read.items():
        s = str(value)
        if id in s:
            values = eval(s.replace(id, app_package))
            element_dict.setdefault(key, values)
        else:
            element_dict.setdefault(key, value)
    return element_dict


if __name__ == '__main__':
    print(get_yaml_data("login.yaml").get("gengxintanchaung"))
